home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 8.0 KB | 293 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: RRectShp.cpp
- // Release Version: $ ODF 2 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef CONSTANT_H
- #include "Constant.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawshapes
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- FW_DEFINE_AUTO(CRoundRectShape)
- FW_DEFINE_CLASS_M1(CRoundRectShape, CBoundedShape)
-
- const FW_ClassTypeConstant LRoundRectShape = FW_TYPE_CONSTANT('s','h','r','r');
- FW_REGISTER_ARCHIVABLE_CLASS(LRoundRectShape, CRoundRectShape, CRoundRectShape::Read, 0, 0, CBaseShape::Write)
-
- //========================================================================================
- // class CRoundRectShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::CRoundRectShape
- //----------------------------------------------------------------------------------------
-
- CRoundRectShape::CRoundRectShape(CDrawPart* drawPart):
- CBoundedShape(drawPart, kRRectShape, kFrameOnly),
- fOvalSize(FW_CPoint(FW_IntToFixed(32), FW_IntToFixed(32)))
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::CRoundRectShape
- //----------------------------------------------------------------------------------------
-
- CRoundRectShape::CRoundRectShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
- CBoundedShape(drawPart, archive)
- {
- archive >> fOvalSize;
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::~CRoundRectShape
- //----------------------------------------------------------------------------------------
-
- CRoundRectShape::~CRoundRectShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::OutlineShape
- //----------------------------------------------------------------------------------------
-
- void CRoundRectShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
- {
- FW_CRect bounds(rect);
- AdjustRectForPenSize(bounds, style.GetPenSize());
- FW_CRoundRectShape::RenderRoundRect(gc,
- bounds,
- fOvalSize,
- FW_kFrame,
- ink, style);
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::RenderShape
- //----------------------------------------------------------------------------------------
-
- void CRoundRectShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
- {
- FW_UNUSED(ev);
- FW_UNUSED(facet);
- FW_CRect rect = GetRectGeometry();
- AdjustRectForPenSize(rect, GetPenSize());
-
- if (HasFillStyle())
- FW_CRoundRectShape::RenderRoundRect(gc, rect, fOvalSize, FW_kFill, fFillInk, fFillStyle);
-
- if (HasFrameStyle())
- FW_CRoundRectShape::RenderRoundRect(gc, rect, fOvalSize, FW_kFrame, fFrameInk, fFrameStyle);
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CRoundRectShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
- {
- FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
-
- FW_CRect bounds = GetRectGeometry();
- AdjustRectForPenSize(bounds, GetPenSize());
-
- FW_CRoundRectShape RRectShape(bounds, fOvalSize, HasFillStyle() ? FW_kFill : FW_kFrame);
- return RRectShape.HitTest(gc, mouse, FW_IntToFixed(2));
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::CalcClipShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CRoundRectShape::CalcClipShape(Environment* ev)
- {
- FW_CRect bounds = GetRectGeometry();
- AdjustRectForPenSize(bounds, GetPenSize());
-
- FW_CAcquiredODShape clipShape = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize);
-
- if (FrameOnly())
- {
- bounds.Inset(GetPenSize(), GetPenSize());
- FW_CAcquiredODShape roundRectShape = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize);
- clipShape->Subtract(ev, roundRectShape);
- }
-
- return clipShape.Orphan();
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::CreateShapeOutline
- //----------------------------------------------------------------------------------------
-
- ODShape* CRoundRectShape::CreateShapeOutline(Environment *ev)
- {
- FW_CRect bounds = GetRectGeometry();
- AdjustRectForPenSize(bounds, GetPenSize());
-
- ODShape* dragRgn = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize); // We don't acquire it because we return it
-
- ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
-
- return dragRgn;
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::Read
- //----------------------------------------------------------------------------------------
-
- void* CRoundRectShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
- // [HLX] This is a hack until I can register object with the archiver
- CDrawReadableStream *drawArchive = (CDrawReadableStream*)&stream;
- return FW_NEW(CRoundRectShape, (drawArchive->GetDrawPart(), stream));
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void CRoundRectShape::Flatten(FW_CWritableStream& archive)
- {
- CBoundedShape::Flatten(archive);
- archive << fOvalSize;
- }
-
- //----------------------------------------------------------------------------------------
- // CRoundRectShape::GetObjectClass
- //----------------------------------------------------------------------------------------
-
- ODDescType CRoundRectShape::GetObjectClass() const
- {
- return cRoundedRectangle;
- }
-